<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/5/27
 * Time: 13:13
 */

namespace app\common\model;


use think\Model;

class Bus extends Model
{

    public function imgs()
    {
        return $this->hasMany('BusImg','bus_id');
    }

    public function business()
    {
        return $this->belongsTo('BusBusiness', 'business_id');
    }

    public function setBeginTimeAttr($value){
        return strtotime($value);
    }

    public function getBeginTimeAttr($value){
        return date('Y-m-d', $value);
    }

    public function getDrivingLicenseAttr($value){
        $host = getImgUrl();
        return $host . "/" .$value;
    }

    public function getCreateTime($value){
        return date('Y-m-d H:i', $value);
    }

    public function getStateAttr($value){
        $stateArr = [1=>'审核中', 2=>'审核通过', 3=>'审核不通过', 4=>'下架'];
        return $stateArr[$value];
    }

    //获取汽车服务年限
    public function getSerYAttr($value, $data){
        $timeDiff = time()-$data['begin_time'];
        return ceil($timeDiff/(60*60*24*365));
    }

}